# ！ /usr/bin/python3
# -*- coding:utf-8 -*-
# @Author:Peng Cao
# @File: 01opencv_img.py
# @Software: PyCharm
import cv2.cv2 as cv2
import matplotlib.pyplot as plt
import numpy as np

# img = cv2.imread('./data/lena.jpg', cv2.IMREAD_GRAYSCALE)
img = cv2.imread('./data/lena.jpg')
img_cat = cv2.imread('./data/cat.jpg')
img_dog = cv2.imread('./data/dog.jpg')
img_dog2 = cv2.resize(img_dog, (500, 414))
# print(img_cat.shape)
print(img_cat.shape)
exit()
print(img_dog2.shape)
img_rh = cv2.addWeighted(img_cat, 0.6, img_dog2, 0.4, 0)
cv2.imshow('图像融合', img_rh)
cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
cv2.destroyAllWindows()
exit()
print(img)
print(img.shape)
new_img = cv2.resize(img, (600, 540))
print(new_img.shape)
new_img2 = cv2.resize(img, (0, 0), fx=2, fy=1)
print(new_img2.shape)
exit()
# print(type(img))
# print(img.size)  # 像素个数
# print(img.dtype)  # 数据类型
# img = img[0:500, 0:500]
# cv2.imshow('image', img)
# cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
# cv2.destroyAllWindows()
# print(img.shape)

# cv2.imwrite('./data/lena_fb.jpg', img=img)  # 保存图片
b, g, r = cv2.split(img)
print("全通道", img)
print("全通道", img.shape)
print("b通道", b)
print("b通道", b.shape)
# print("g通道", g)
# print("r通道", r)
cv2.imshow('b通道', b)
cv2.waitKey(0)
exit()
img = cv2.merge((b, g, r))
# cv2.imshow('image', img)
# cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
# cv2.destroyAllWindows()

# 保留b通道
cur_img = img.copy()
cur_img[:, :, 1] = 0
cur_img[:, :, 2] = 0
cv2.imshow('image', cur_img)
cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
cv2.destroyAllWindows()
# 保留g通道
cur_img = img.copy()
cur_img[:, :, 0] = 0
cur_img[:, :, 2] = 0
cv2.imshow('image', cur_img)
cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
cv2.destroyAllWindows()
# 保留r通道
cur_img = img.copy()
cur_img[:, :, 0] = 0
cur_img[:, :, 1] = 0
cv2.imshow('image', cur_img)
cv2.waitKey(0)  # 等待时间，如1000，等待1秒，设置为0，表示按任意键结束
cv2.destroyAllWindows()
# 边界填充
